from django.shortcuts import render
from django.http import HttpResponseRedirect, Http404, HttpResponse
from django.views.generic import View
from django.core.urlresolvers import reverse

from django_rq import job
from redis import Redis

from spider.link import get_inner_link
from spider.models import Page, Link


@job('download', connection=Redis(), timeout=100)
def crawl(url):
    pass


def display(request):
    links = get_inner_link('http://www.szu.edu.cn')
    Page.update(links)
    Link.update('http://www.szu.edu.cn', {t[0] for t in links})
    return HttpResponse(links)


class SearchView(View):

    def get(self, request):
        return render(request, 'search.html')

    def post(self, request):
        pass

